
# 1.新建文件 `第二周_第二节tmp.py` 完成上面关于字符串CRUD的操作实践, 并附上返回结果, 格式如下
# 'a' + 'b'
# 'ab'

# create加法
x = 'a'
y = 'b'
x += y
print(x)
# result：'ab'

# retrieve检索
list_s = 'abcdefghijklmnopqrstuvwxyz'
learn = list_s[15] + list_s[24] + list_s[19] + list_s[7] + list_s[14] + list_s[13]
print(learn)
# result：python

# update更新
list_0 = 'I want learn python'
list_1 = list_0.replace('want', 'like')
# 替换
list_2 = list_1.split(' ')
# 分割
list_3 = '-'.join(list_2)
# 合并
print(list_1, '\n', list_2, '\n', list_3, '\n')
# result：I like learn python
# result：['I', 'like', 'learn', 'python']
# result：I-like-learn-python

# delete删除
list_d = '[I like learn python]'
x = list_d.strip('[]')
print(x)
# result: I like learn python

# 2.完成对字符串格式化的实践, 按上述格式
# city = 'shanghai'
# f"{city}-tunan"
# shanghai-tuann

# 按传入参数的默认顺序
eg1 = '{} {} {} {}'.format('I', 'like', 'learn', 'python')
print(eg1)
# result:I like learn python

# 按指定参数索引
list_22 = 'abcdefghijklmnopqrstuvwxyz'
list_33 = list(list_22)
eg2 = '{15}{24}{19}{7}{14}{13}'.format(*list_33)
print(eg2)
# result:python

# 按关键词参数
eg3 = "{who} {how} {what}".format(who="I", how="like learn", what="python")
print(eg3)
# result:I like learn python

# 按变量
who = "I"
how = "like learn"
what = "python"
eg4 = f'{who} {how} {what}'
print(eg4)
# result:I like learn python

# 读取当前`第二周_第二节tmp.py`并写入到新文件中`第二周_第二节.py`, 上传到码云.

# 读取写入文件

f = open('week2_section2.py', "w", encoding="utf-8")
file = open('week2_section2tmp.py', "r", encoding="utf-8")
f.write(file.read())
f.close()
file.close()